$(function () {
    //---------加载时间---开始
    initIndexTime();
    //---------加载时间---结束

    //基本数据统计--------------开始
    /**
     * 获取基本数据
     * @param callback
     */
    function examBaseCount(callback) {
        $.ajax({
            url:baseloaction +'/admin/count/examBaseCount',
            type:'post',
            dataType:'json',
            success:function (result) {
                if(result.success==true){
                    callback(result.entity);
                }
            }
        });
    }
    examBaseCount(function (data) {
        var userCountMap = data.userCountMap;
        var buyUserNum = userCountMap.buyUserNum;
        $("#buyExamUserNum").text(buyUserNum);
        var examCountMap = data.examCountMap;
        var sumQuestionNum = examCountMap.sumQuestionNum;
        $("#sumQuestionNum").text(sumQuestionNum);
        var sumExamNum = examCountMap.sumExamNum;
        $("#sumExamNum").text(sumExamNum);
    });
    //基本数据统计--------------结束


    //易错考点前 10 (综合版)--------------开始
    /**
     *加载数据
     * @param callback
     */
    function queryQuestionRecordPointCountData(callback) {
        $.ajax({
            url: baseloaction +'/admin/count/queryQuestionRecordPointCount',
            type:'post',
            dataType:'json',
            async:false,
            success:function (result) {
                if(result.success==true){
                    callback(result.entity);
                }
            }
        });
    }
    //显示数据
    queryQuestionRecordPointCountData(function (data) {
        if(data!=null){
            var nameList = new Array();
            var dataList = new Array();
            for(var i=0;i<data.length;i++){
                var obj = data[i];
                var pointList = obj.pointList
                var pointNames = '';
                $.each(pointList,function (index,em) {
                    if(index < pointList.length -1){
                        pointNames +=em.pointName+',';
                    }else{
                        pointNames +=em.pointName;
                    }
                });
                nameList.push(pointNames);
                var _data = {};
                _data.name=pointNames;
                _data.value=obj.questionNum;
                dataList.push(_data)
            }
            var lineChart = echarts.init(document.getElementById("exam-echarts-map-chart"));
            var lineoption = {
                tooltip: {
                    trigger: 'item',
                    formatter: "{a} <br/>{b}: {c} ({d}%)"
                },
                legend: {
                    orient: 'vertical',
                    x: 'left',
                    data:nameList
                },
                series: [
                    {
                        name:'访问来源',
                        type:'pie',
                        radius: ['50%', '70%'],
                        avoidLabelOverlap: false,
                        label: {
                            normal: {
                                show: false,
                                position: 'center'
                            },
                            emphasis: {
                                show: true,
                                textStyle: {
                                    fontSize: '30',
                                    fontWeight: 'bold'
                                }
                            }
                        },
                        labelLine: {
                            normal: {
                                show: false
                            }
                        },
                        data:dataList
                    }
                ]
            };
            lineChart.setOption(lineoption);
            $(window).resize(lineChart.resize);
        }
    });
    //易错考点前 10 (综合版)--------------结束

    //试卷使用排行 前10(综合版)-----------开始
    /**
     * 查询数据
     * @param callback
     */
    function queryExamRecordCountNumData(callback) {
        $.ajax({
            url: baseloaction +'/admin/count/queryExamRecordCount',
            type:'post',
            dataType:'json',
            async:false,
            success:function (result) {
                if(result.success==true){
                    callback(result.entity);
                }
            }
        });
    }

    /**
     * 加载显示数据
     */
    queryExamRecordCountNumData(function (data) {
        if(data!=null){
            var nameList = new Array();
            var dataList = new Array();
            for(var i=0;i<data.length;i++){
                var obj = data[i];
                nameList.push(obj.examName);
                var _obj = {};
                _obj.name = obj.examName;
                _obj.value = obj.examNum;
                dataList.push(_obj);
            }
            var lineChart = echarts.init(document.getElementById("exam-echarts-pie-chart"));
            var lineoption = {
                tooltip: {
                    trigger: 'item',
                    formatter: "{a} <br/>{b}: {c} ({d}%)"
                },
                legend: {
                    orient: 'vertical',
                    x: 'left',
                    data:nameList
                },
                series: [
                    {
                        name:'访问来源',
                        type:'pie',
                        radius: ['50%', '70%'],
                        avoidLabelOverlap: false,
                        label: {
                            normal: {
                                show: false,
                                position: 'center'
                            },
                            emphasis: {
                                show: true,
                                textStyle: {
                                    fontSize: '30',
                                    fontWeight: 'bold'
                                }
                            }
                        },
                        labelLine: {
                            normal: {
                                show: false
                            }
                        },
                        data:dataList
                    }
                ]
            };
            lineChart.setOption(lineoption);
            $(window).resize(lineChart.resize);
        }
    });
    //试卷使用排行 前10(综合版)-----------结束
});